package com.yzl.springboot.springboot.handler;
import com.yzl.springboot.springboot.utils.JsonData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @Title: CustomExtHandler
 * @Author: 姚志立
 * @Description:标明这是一个异常处理
 * @Date: 2020/5/25 1:43
 * @Version: 1.0
 */

//@RestControllerAdvice
//public class CustomExtHandler {
//    @ExceptionHandler(value = Exception.class)
//    JsonData handlerException(Exception e, HttpServletRequest request){
//        return JsonData.buildError(-2,"服务端出问题了");
//    }
//}
@ControllerAdvice
public class CustomExtHandler {
    @ExceptionHandler(value = Exception.class)
    Object handlerException(Exception e, HttpServletRequest request){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error.html");
        System.out.println(e.getMessage());
        modelAndView.addObject("msg",e.getMessage());
        return modelAndView;
    }
}
